package com.anmong.cloud.cloudadmin.service;

import com.anmong.cloud.cloudadmin.service.feign.TestFeignService;
import com.anmong.cloud.cloudapi.dto.TestUpdateDTO;
import com.anmong.cloud.cloudapi.entity.SysOperateLog;
import com.anmong.cloud.cloudapi.entity.SysUser;
import com.anmong.cloud.cloudapi.mapper.SysOperateLogMapper;
import com.anmong.cloud.cloudapi.mapper.SysUserMapper;
import com.anmong.cloud.cloudcommon.util.IDUtil;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class TestSysUserService {

    @Autowired
    private TestFeignService testFeignService;
    @Autowired
    private SysOperateLogMapper sysOperateLogMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    @GlobalTransactional
    public SysUser testUpdate(TestUpdateDTO dto){
        LocalDateTime now = LocalDateTime.now();
        SysOperateLog sysOperateLog = new SysOperateLog();
        sysOperateLog.setId(IDUtil.get());
        sysOperateLog.setCreateTime(now);
        sysOperateLog.setUpdateTime(now);
        sysOperateLog.setCreateUser(dto.getId());
        //sysOperateLogMapper.insert(sysOperateLog);
        dto.setUpdateTime(now);
        SysUser sysUser = testFeignService.update(dto);
        //int a = 1/0;
        return sysUser;
    }

    public List<SysUser> list(){
        return testFeignService.list();
    }

    public void empty(){
        testFeignService.empty();
    }

    public SysUser findById(Long id){
        return sysUserMapper.selectById(id);
    }
}
